package com.maigao.util;


import org.slf4j.LoggerFactory;

public class Logger {
    private final static org.slf4j.Logger LOGGER;

    static {
        StackTraceElement[] stackTrace = new Exception().getStackTrace();
        if (stackTrace.length > 1) {
            LOGGER = LoggerFactory.getLogger(stackTrace[1].getClassName());
        } else {
            LOGGER = LoggerFactory.getLogger(stackTrace[0].getClassName());
        }
    }
    public static void infoObject(Object content) {
        info(content.getClass().getSimpleName(), ":", JsonUtil.toJson(content));
    }

    public static void info(String content) {
        LOGGER.info(content);
    }

    public static void info(String title, String content) {
        content = String.format("%s:%s", getPrefix(title), content);
        LOGGER.info(content);
    }

    public static void info(String title, Object content) {
        String cnt = String.format("%s:%s", getPrefix(title), JsonUtil.toJson(content));
        LOGGER.info(cnt);
    }

    public static void info(String title, String content, Object... objs) {
        content = String.format("%s:%s", getPrefix(title), content);
        LOGGER.info(content, objs);
    }

    public static void info(String content, Object... objs) {
        LOGGER.info(content, objs);
    }

    public static void warn(String content) {
        LOGGER.warn(content);
    }

    public static void warn(String title, String content) {
        content = String.format("%s:%s", getPrefix(title), content);
        LOGGER.warn(content);
    }

    public static void warn(String title, String content, Object... objs) {
        content = String.format("%s:%s", getPrefix(title), content);
        LOGGER.warn(content, objs);
    }

    public static void error(String content) {
        LOGGER.error(content);
    }

    public static void error(String title, String content) {
        content = String.format("%s:%s", getPrefix(title), content);
        LOGGER.error(content);
    }

    public static void error(String title, String content, Object... objs) {
        content = String.format("%s:%s", getPrefix(title), content);
        LOGGER.error(content, objs);
    }

    public static void error(String content, Object... objs) {
        LOGGER.error(content, objs);
    }


    private static String getPrefix(String title) {
        return String.format("RZ_%s", title);
    }

    public static void main(String[] args) {
        Logger.info("测试：{}，参数：{}", "a", "b");

    }
}
